﻿namespace ToRTalent {
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Media.Imaging;

    public partial class TalentTree : UserControl {
        public TalentTree() {
            InitializeComponent();
        }

        private const string _talentTreeNumberName = "TreeNumber";

        /// <summary>
        /// Property variable for the XAML TreeNumber property
        /// </summary>
        public static readonly DependencyProperty TreeNumberProperty = DependencyProperty.Register( _talentTreeNumberName, typeof( int ),
                                typeof( TalentTree ), new PropertyMetadata( -1 ) );

        /// <summary>
        /// Gets or sets the tree number for this TalentTree control
        /// </summary>
        public int TreeNumber {
            get { return ( int )GetValue( TreeNumberProperty ); }
            set {
                SetValue( TreeNumberProperty, value );
                if( value >= 0 && value < 3 )
                    TreePanel.Tree = value;
            }
        }

        private string _treeName = String.Empty;

        /// <summary>
        /// Gets or sets the tree name value, 
        /// as well as sets the label reflecting the tree name
        /// </summary>
        public string TreeName {
            get { return _treeName; }
            set {
                if( value != null ) {
                    _treeName = value;
                }
            }
        }

        
        private bool _isRepublic;

        /// <summary>
        /// Gets or sets a value indicating if the selected class is republic or not. 
        /// Also sets the talent panel border using the given value.
        /// </summary>
        public bool IsRepublic {
            get { return _isRepublic; }
            set {
                _isRepublic = value;

                LinearGradientBrush borderBrush = new LinearGradientBrush();
                GradientStop topGradStop = new GradientStop();
                GradientStop bottomGradStop = new GradientStop();

                borderBrush.StartPoint = new Point( 0.5, 0 );
                borderBrush.EndPoint = new Point( 0.5, 1 );
                topGradStop.Offset = 0.331;
                bottomGradStop.Offset = 1;
                topGradStop.Color = _isRepublic ? Color.FromArgb( 0xFF, 0x0E, 0x8B, 0xC8 ) :
                                                  Color.FromArgb( 0xFF, 0xA7, 0x0D, 0x0D );

                bottomGradStop.Color = _isRepublic ? Color.FromArgb( 0x00, 0x0E, 0x8B, 0xC8 ) :
                                                     Color.FromArgb( 0x00, 0xA7, 0x0D, 0x0D );

                borderBrush.GradientStops.Add( topGradStop );
                borderBrush.GradientStops.Add( bottomGradStop );
                TreeBorder.Fill = borderBrush;
            }
        }

        private void ResetButtonMouseHover( object sender, MouseEventArgs e ) {
            ResetButton.Source = new BitmapImage( new Uri( @"Images/Buttons/ResetBtnHover.png", UriKind.Relative ) );
        }

        private void ResetButtonMouseLeave( object sender, MouseEventArgs e ) {
            ResetButton.Source = new BitmapImage( new Uri( @"Images/Buttons/ResetBtnRest.png", UriKind.Relative ) );
        }

        private void ResetButtonMouseClick( object sender, MouseButtonEventArgs e ) {
            TreePanel.ResetPanel();
        }

        public void StartAnimation() {
            FadeIn.Begin();
        }

        public bool IsHidden {
            get { return LayoutGrid.Opacity == 0; }
        }
    }
}
